{{ if and .Site.Params.enableServiceWorker (eq hugo.Environment "production") }}
    {{- $sw := resources.Get "js/sw.js" -}}
    {{- $dummy := "" | resources.FromString "dummy.js" -}}
    {{- $url := (slice $sw $dummy | resources.Concat "sw.js").RelPermalink -}}

    <script>
        if ('serviceWorker' in navigator) {
            window.addEventListener('load', function() {
                navigator.serviceWorker.register('{{ $url }}');
            });
        }
    </script>
{{ end }}
